package com.newenergy.wisehome.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.newenergy.wisehome.R;
import com.newenergy.wisehome.common.util.ImageUtil;
import com.newenergy.wisehome.data.bean.Icon;

import java.util.List;

/**
 * Created by jnl on 2017/9/14.
 */

public class IconAdapter extends RecyclerArrayAdapter<Icon> {

    public Context mContext;

    public void refreshData(List<Icon> data) {
        clear();
        if (data != null) addAll(data);
        notifyDataSetChanged();
    }

    public IconAdapter(Context context) {
        super(context);
        mContext=context.getApplicationContext();
    }
    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int
            viewType) {
        return new ViewHolder(parent);
    }

    private class ViewHolder extends BaseViewHolder<Icon> {

        private ImageView iv_icon;


        public ViewHolder(ViewGroup parent) {
            super(parent, R.layout.list_icon);
            iv_icon = $(R.id.iv_icon);
        }


        @Override
        public void setData(Icon data) {
            super.setData(data);
            iv_icon.setImageResource(ImageUtil.getImageId(data.getIconName()));
        }
    }
}
